class Test():
    def __enter__(self):
        print('enter')
        return 666
                    #异常类型
    def __exit__(self, exc_type, exc_val, exc_tb):
        print(self, exc_type, exc_val, exc_tb)
        import traceback
        print(traceback.extract_tb(exc_tb))#打印出现错误的模块跟位置
        print('exit')
        return True #异常不会被抛出到外界

with Test() as f:
    print('body',f)
    1/0